package com.itheima.controller;

import com.itheima.common.Result;
import com.itheima.dto.UserLogDTO;
import com.itheima.service.HomeIndexService;
import com.itheima.vo.HomeDataVO;
import com.itheima.vo.UserLoginVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequiredArgsConstructor
@Slf4j
public class HomeIndexController {
    private final HomeIndexService indexService;
    private final HttpServletRequest request;

    @PostMapping("/home/index/login")
    public Result<?> login(@RequestBody UserLogDTO userLoginDTO) {
        UserLoginVO userLoginVO = indexService.login(userLoginDTO);
        log.info("数据是-->{}", userLoginVO);
        return Result.success(userLoginVO);
    }

    @GetMapping("/user/getUserInfo")
    public Result<HomeDataVO> getUserInfo() {
        HomeDataVO homeDataVO = indexService.getUserInfo();
        String token = request.getHeader("token");
        homeDataVO.setToken(token);
        return Result.success(homeDataVO);
    }
}
